<script setup>
import { ref, onMounted } from "vue";
import { useRouter } from "vue-router";
import { getOverviewApi } from "@/api/report";
import { ElMessage } from "element-plus";

const router = useRouter();

// 概览数据
const overviewData = ref({
  clueTotal: 0,
  clueWaitAllot: 0,
  clueWaitFollow: 0,
  clueFollowing: 0,
  clueFalse: 0,
  clueConvertBusiness: 0,
  businessTotal: 0,
  businessWaitAllot: 0,
  businessWaitFollow: 0,
  businessFollowing: 0,
  businessFalse: 0,
  businessConvertCustomer: 0,
});

// 快捷操作卡片数据
const quickActions = ref([
  {
    title: "课程管理",
    subtitle: "课程信息维护",
    icon: "Reading",
    route: "/resource/course",
    color: "#409EFF",
  },
  {
    title: "活动管理",
    subtitle: "营销活动管理",
    icon: "Promotion",
    route: "/resource/activity",
    color: "#67C23A",
  },
  {
    title: "线索管理",
    subtitle: "潜在客户追踪",
    icon: "User",
    route: "/clue/list",
    color: "#E6A23C",
  },
  {
    title: "商机管理",
    subtitle: "销售机会管理",
    icon: "Opportunity",
    route: "/business/list",
    color: "#F56C6C",
  },
  {
    title: "客户管理",
    subtitle: "客户信息维护",
    icon: "Avatar",
    route: "/customer",
    color: "#909399",
  },
  {
    title: "日志统计",
    subtitle: "系统操作日志",
    icon: "Document",
    route: "/system/log",
    color: "#9C27B0",
  },
]);

// 获取概览数据
const getOverview = async () => {
  try {
    const result = await getOverviewApi();
    if (result.code === 1) {
      overviewData.value = result.data;
    } else {
      ElMessage.error(result.msg || "获取概览数据失败");
    }
  } catch (error) {
    console.error("获取概览数据失败:", error);
    ElMessage.error("获取概览数据失败，请重试");
  }
};

// 跳转到对应页面
const goToPage = (route) => {
  router.push(route);
};

// 页面加载时获取数据
onMounted(() => {
  getOverview();
});
</script>

<template>
  
  <div class="home-container">
    <!-- 欢迎标题 -->
    <div class="welcome-header">
      <h1>欢迎您, 进入轻客管家系统</h1>
    </div>

    <!-- 概览区域 -->
    <div class="overview-section">
      <!-- 线索概览 -->
      <el-card class="overview-card" shadow="hover">
        <template #header>
          <div class="card-header">
            <el-icon class="header-icon" color="#409EFF"><User /></el-icon>
            <span>线索概览</span>
          </div>
        </template>
        <div class="overview-grid">
          <div class="overview-item">
            <div class="item-number">{{ overviewData.clueTotal }}</div>
            <div class="item-label">总线索数</div>
          </div>
          <div class="overview-item">
            <div class="item-number">{{ overviewData.clueWaitAllot }}</div>
            <div class="item-label">待分配线索数</div>
          </div>
          <div class="overview-item">
            <div class="item-number">{{ overviewData.clueWaitFollow }}</div>
            <div class="item-label">待跟进线索数</div>
          </div>
          <div class="overview-item">
            <div class="item-number">{{ overviewData.clueFollowing }}</div>
            <div class="item-label">跟进中线索数</div>
          </div>
          <div class="overview-item">
            <div class="item-number">{{ overviewData.clueFalse }}</div>
            <div class="item-label">伪线索数</div>
          </div>
          <div class="overview-item">
            <div class="item-number">
              {{ overviewData.clueConvertBusiness }}
            </div>
            <div class="item-label">转商机线索数</div>
          </div>
        </div>
      </el-card>

      <!-- 商机概览 -->
      <el-card class="overview-card" shadow="hover">
        <template #header>
          <div class="card-header">
            <el-icon class="header-icon" color="#67C23A"
              ><Opportunity
            /></el-icon>
            <span>商机概览</span>
          </div>
        </template>
        <div class="overview-grid">
          <div class="overview-item">
            <div class="item-number">{{ overviewData.businessTotal }}</div>
            <div class="item-label">总商机数</div>
          </div>
          <div class="overview-item">
            <div class="item-number">{{ overviewData.businessWaitAllot }}</div>
            <div class="item-label">待分配商机数</div>
          </div>
          <div class="overview-item">
            <div class="item-number">{{ overviewData.businessWaitFollow }}</div>
            <div class="item-label">待跟进商机数</div>
          </div>
          <div class="overview-item">
            <div class="item-number">{{ overviewData.businessFollowing }}</div>
            <div class="item-label">跟进中商机数</div>
          </div>
          <div class="overview-item">
            <div class="item-number">{{ overviewData.businessFalse }}</div>
            <div class="item-label">回收商机数</div>
          </div>
          <div class="overview-item">
            <div class="item-number">
              {{ overviewData.businessConvertCustomer }}
            </div>
            <div class="item-label">转客户商机数</div>
          </div>
        </div>
      </el-card>
    </div>

    <!-- 快捷操作区域 -->
    <div class="quick-actions-section">
      <h2>快捷操作</h2>
      <div class="actions-grid">
        <div
          v-for="action in quickActions"
          :key="action.title"
          class="action-card"
          :style="{ borderLeftColor: action.color }"
          @click="goToPage(action.route)"
        >
          <div class="action-icon" :style="{ color: action.color }">
            <el-icon :size="32">
              <component :is="action.icon" />
            </el-icon>
          </div>
          <div class="action-content">
            <div class="action-title">{{ action.title }}</div>
            <div class="action-subtitle">{{ action.subtitle }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.home-container {
  padding: 20px;
  background: linear-gradient(
    135deg,
    #ffffff 0%,
    #f8fafc 25%,
    #f1f5f9 50%,
    #f8fafc 75%,
    #ffffff 100%
  );
  min-height: 100%;
  position: relative;
  overflow: hidden;
}

.home-container::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(
      circle at 20% 80%,
      rgba(59, 130, 246, 0.03) 0%,
      transparent 50%
    ),
    radial-gradient(
      circle at 80% 20%,
      rgba(139, 92, 246, 0.03) 0%,
      transparent 50%
    ),
    url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><radialGradient id="grid"><stop offset="0%" stop-color="rgba(59,130,246,0.05)"/><stop offset="100%" stop-color="transparent"/></radialGradient></defs><rect x="0" y="0" width="100" height="100" fill="url(%23grid)" opacity="0.2"/></svg>');
  animation: techFloat 30s ease-in-out infinite;
}

@keyframes techFloat {
  0%,
  100% {
    opacity: 0.2;
    transform: scale(1);
  }
  50% {
    opacity: 0.4;
    transform: scale(1.02);
  }
}

.welcome-header {
  text-align: center;
  margin-bottom: 40px;
  padding: 40px 0;
  background: linear-gradient(135deg, #3b82f6 0%, #6366f1 50%, #8b5cf6 100%);
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(59, 130, 246, 0.2),
    0 0 60px rgba(139, 92, 246, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(59, 130, 246, 0.3);
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.welcome-header:hover {
  transform: translateY(-5px) scale(1.02);
  box-shadow: 0 20px 40px rgba(59, 130, 246, 0.3),
    0 0 80px rgba(139, 92, 246, 0.2);
}

.welcome-header::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(
    90deg,
    transparent,
    #60a5fa,
    #a78bfa,
    #60a5fa,
    transparent
  );
  animation: techScan 3s ease-in-out infinite;
}

@keyframes techScan {
  0% {
    transform: translateX(-100%);
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
  100% {
    transform: translateX(100%);
    opacity: 0;
  }
}

.welcome-header h1 {
  color: #ffffff;
  font-size: 60px;
  font-family: "楷体", "KaiTi", serif;
  font-weight: 600;
  margin: 0;
  text-shadow: 0 0 20px rgba(59, 130, 246, 0.5);
  position: relative;
  z-index: 1;
  transition: all 0.3s ease;
}

.welcome-header:hover h1 {
  transform: scale(1.05);
  text-shadow: 0 0 30px rgba(59, 130, 246, 0.8);
}

.overview-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 30px;
  margin-bottom: 40px;
}

.overview-card {
  border-radius: 16px;
  border: 1px solid rgba(59, 130, 246, 0.2);
  background: #ffffff;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.08), 0 0 40px rgba(59, 130, 246, 0.05),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  backdrop-filter: blur(10px);
  position: relative;
  cursor: pointer;
}

.overview-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, #3b82f6, #8b5cf6, #3b82f6);
  animation: techFlow 4s linear infinite;
}

@keyframes techFlow {
  0% {
    background-position: 0% 50%;
  }
  100% {
    background-position: 100% 50%;
  }
}

.overview-card:hover {
  transform: translateY(-12px) scale(1.02);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15), 0 0 80px rgba(59, 130, 246, 0.2);
  border-color: rgba(59, 130, 246, 0.5);
}

.overview-card:active {
  transform: translateY(-8px) scale(0.98);
  transition: all 0.1s ease;
}

.card-header {
  display: flex;
  align-items: center;
  font-weight: 600;
  font-size: 18px;
  padding: 20px 0 10px 0;
  color: #3b82f6;
  text-shadow: 0 0 10px rgba(59, 130, 246, 0.2);
  transition: all 0.3s ease;
}

.overview-card:hover .card-header {
  color: #1e40af;
  transform: translateX(5px);
}

.header-icon {
  margin-right: 12px;
  font-size: 24px;
  padding: 12px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  border-radius: 50%;
  color: white !important;
  box-shadow: 0 0 20px rgba(59, 130, 246, 0.3), 0 0 40px rgba(139, 92, 246, 0.2);
  animation: techPulse 2s ease-in-out infinite;
  transition: all 0.3s ease;
}

.overview-card:hover .header-icon {
  transform: scale(1.1) rotate(5deg);
  box-shadow: 0 0 30px rgba(59, 130, 246, 0.5), 0 0 60px rgba(139, 92, 246, 0.4);
}

@keyframes techPulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  padding: 10px 0;
}

.overview-item {
  text-align: center;
  padding: 20px 16px;
  background: linear-gradient(
    135deg,
    rgba(59, 130, 246, 0.05) 0%,
    rgba(139, 92, 246, 0.05) 100%
  );
  border-radius: 12px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid rgba(59, 130, 246, 0.1);
  position: relative;
  overflow: hidden;
  cursor: pointer;
}

.overview-item::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(59, 130, 246, 0.15),
    transparent
  );
  transition: left 0.6s;
}

.overview-item:hover::before {
  left: 100%;
}

.overview-item:hover {
  background: linear-gradient(
    135deg,
    rgba(59, 130, 246, 0.1) 0%,
    rgba(139, 92, 246, 0.1) 100%
  );
  transform: translateY(-5px) scale(1.03);
  box-shadow: 0 12px 25px rgba(0, 0, 0, 0.1), 0 0 40px rgba(59, 130, 246, 0.15);
  border-color: rgba(59, 130, 246, 0.3);
}

.overview-item:active {
  transform: translateY(-2px) scale(0.98);
  transition: all 0.1s ease;
}

.item-number {
  font-size: 28px;
  font-weight: 800;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 10px;
  text-shadow: none;
  transition: all 0.3s ease;
}

.overview-item:hover .item-number {
  transform: scale(1.1);
  filter: brightness(1.2);
}

.item-label {
  font-size: 13px;
  color: #64748b;
  line-height: 1.4;
  font-weight: 500;
  transition: all 0.3s ease;
}

.overview-item:hover .item-label {
  color: #3b82f6;
  transform: translateY(-2px);
}

.quick-actions-section {
  background: #ffffff;
  border-radius: 20px;
  padding: 30px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.08), 0 0 40px rgba(59, 130, 246, 0.05),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(59, 130, 246, 0.2);
  backdrop-filter: blur(10px);
  transition: all 0.3s ease;
}

.quick-actions-section:hover {
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.12), 0 0 50px rgba(59, 130, 246, 0.08);
}

.quick-actions-section h2 {
  color: #3b82f6;
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 25px 0;
  text-align: center;
  position: relative;
  text-shadow: 0 0 15px rgba(59, 130, 246, 0.2);
  transition: all 0.3s ease;
}

.quick-actions-section:hover h2 {
  color: #1e40af;
  transform: scale(1.05);
}

.quick-actions-section h2::after {
  content: "";
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 80px;
  height: 3px;
  background: linear-gradient(90deg, #3b82f6, #8b5cf6);
  border-radius: 2px;
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.3);
  transition: all 0.3s ease;
}

.quick-actions-section:hover h2::after {
  width: 100px;
  box-shadow: 0 0 15px rgba(59, 130, 246, 0.5);
}

.actions-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 25px;
}

.action-card {
  display: flex;
  align-items: center;
  padding: 25px 20px;
  background: linear-gradient(
    135deg,
    rgba(59, 130, 246, 0.05) 0%,
    rgba(139, 92, 246, 0.05) 100%
  );
  border: 1px solid rgba(59, 130, 246, 0.1);
  border-left: 4px solid;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.action-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    135deg,
    rgba(59, 130, 246, 0.1),
    rgba(139, 92, 246, 0.1)
  );
  opacity: 0;
  transition: opacity 0.3s;
}

.action-card:hover::before {
  opacity: 1;
}

.action-card:hover {
  border-color: rgba(59, 130, 246, 0.3);
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.15), 0 0 60px rgba(59, 130, 246, 0.15);
  transform: translateY(-8px) scale(1.02);
}

.action-card:active {
  transform: translateY(-4px) scale(0.98);
  transition: all 0.1s ease;
}

.action-icon {
  margin-right: 18px;
  padding: 12px;
  background: rgba(59, 130, 246, 0.1);
  border-radius: 50%;
  transition: all 0.3s ease;
  border: 1px solid rgba(59, 130, 246, 0.15);
}

.action-card:hover .action-icon {
  background: rgba(59, 130, 246, 0.2);
  transform: scale(1.15) rotate(5deg);
  box-shadow: 0 0 30px rgba(59, 130, 246, 0.3);
}

.action-content {
  flex: 1;
  transition: all 0.3s ease;
}

.action-card:hover .action-content {
  transform: translateX(5px);
}

.action-title {
  font-size: 17px;
  font-weight: 700;
  color: #3b82f6;
  margin-bottom: 6px;
  transition: all 0.3s ease;
  text-shadow: 0 0 10px rgba(59, 130, 246, 0.2);
}

.action-subtitle {
  font-size: 13px;
  color: #64748b;
  line-height: 1.4;
  font-weight: 500;
  transition: all 0.3s ease;
}

.action-card:hover .action-title {
  color: #1e40af;
  text-shadow: 0 0 15px rgba(30, 64, 175, 0.3);
  transform: scale(1.05);
}

.action-card:hover .action-subtitle {
  color: #3b82f6;
}

/* 增强的科技感淡入动画 */
@keyframes techFadeIn {
  from {
    opacity: 0;
    transform: translateY(40px) scale(0.9) rotateX(10deg);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1) rotateX(0deg);
  }
}

.overview-card {
  animation: techFadeIn 1s ease-out;
}

.overview-card:nth-child(2) {
  animation-delay: 0.3s;
}

.action-card {
  animation: techFadeIn 1s ease-out;
}

.action-card:nth-child(1) {
  animation-delay: 0.1s;
}
.action-card:nth-child(2) {
  animation-delay: 0.2s;
}
.action-card:nth-child(3) {
  animation-delay: 0.3s;
}
.action-card:nth-child(4) {
  animation-delay: 0.4s;
}
.action-card:nth-child(5) {
  animation-delay: 0.5s;
}
.action-card:nth-child(6) {
  animation-delay: 0.6s;
}

/* 添加微交互效果 */
@keyframes subtleBounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-2px);
  }
}

.overview-item:hover {
  animation: subtleBounce 0.6s ease-in-out;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .overview-section {
    grid-template-columns: 1fr;
  }

  .actions-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .overview-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .actions-grid {
    grid-template-columns: 1fr;
  }

  .welcome-header h1 {
    font-size: 36px;
  }

  .welcome-header {
    padding: 20px 0;
    margin-bottom: 30px;
  }

  .overview-section {
    gap: 20px;
    margin-bottom: 30px;
  }

  .quick-actions-section {
    padding: 20px;
  }
}
</style>
